package com.example.onion.hxchat.mvvm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import com.example.onion.hxchat.room.entity.Apply;
import com.example.onion.hxchat.room.entity.TeamNotification;
import com.example.onion.hxchat.room.repositorywc.ApplyRepository;
import com.example.onion.hxchat.room.repositorywc.TeamNotificationRepository;
import com.example.room.repository.TeamRepository;

import java.util.List;

/**
 * @author:onion
 */
public class TeamNotificationViewModel extends AndroidViewModel {

    //将“秒钟”这个字段用MutableLiveData包装起来
    //LiveData是一个抽象类，不能直接使用，所以通常我们使用它的直接子类MutableLiveData。
    private LiveData<List<TeamNotification>> teamNotifications;
    TeamNotificationRepository repository;

    public TeamNotificationViewModel(@NonNull Application application) {
        super(application);
        repository = new TeamNotificationRepository(application);
    }

    /**
     * 获得ownerId的收到的队伍相关通知消息
     * @param ownerId
     * @return
     */
    public LiveData<List<TeamNotification>> getOwnerIdTeamNotification(String ownerId) {
        return repository.getTeamNotificationCur(ownerId);
    }

    /**
     * 保存接收到的队伍相关的通知消息
     *
     * @param teamNotifications
     */
    public void insertTeamNotification(TeamNotification... teamNotifications) {
        repository.insertTeamNotification(teamNotifications);
    }

    /**
     * 删除接收到的队伍相关的通知消息
     * @param teamNotifications
     */
    public void deleteTeamNotification(TeamNotification... teamNotifications) {
        repository.deleteTeamNotification(teamNotifications);
    }



    //LiveData的作用就是，在ViewModel中的数据发生变化时通知页面。

    @Override
    protected void onCleared() {
        super.onCleared();
    }
}

